#!/bin/bash

case $1 in 
    -h)
        HEAD=TRUE ;;
    -i)
        INFO=TRUE ;;
esac

if ps -ef | egrep 'MacOS/iTunes ' | grep -v grep > /dev/null 2>&1
    then
    state=$(osascript -e 'tell application "iTunes" to player state as string')
    if [ $state = "playing" ]
        then
        artist=$(osascript -e 'tell application "iTunes" to artist of current track as string')
        track=$(osascript -e 'tell application "iTunes" to name of current track as string')
        #echo -e "iTunes Track:\n\t$artist - $track"
        if [[ -n "$HEAD" ]]
            then echo -e "iTunes - Now Playing\n"
        elif [[ -n "$INFO" ]]
            then
            echo -e "Artist: $artist"
            echo -e "Track: $track"
        else
            echo -e "iTunes - Now Playing\n"
            echo -e "Artist: $artist"
            echo -e "Track: $track"
        fi
    fi
fi

